﻿
using System;
using System.Collections.Generic ;

using MskEdit.Sdk ;


namespace MskEdit.Dxf.Model
{
    public static  class DxfCollection<T> where T : class 
    {

        public delegate T TryItemFromHandler( string [] allLines, ref int lineNo, T fallbackValue ) ;


        public static T[] getItems( string [] allLines, SdkSubrange subrange, TryItemFromHandler tryFrom ) {
        
            List<T> itemList = new List<T>() ;
            
            for ( int i = subrange.Begin + 2; i < subrange.End - 1; i += 2 ) {
                    
                // TODO: Why does this work? i skips 2 for each iteration!
                T item = tryFrom( allLines, ref i, null ) ;
                if ( item != null )
                    itemList.Add( item ) ;
                    
            } ;
           
            return itemList.ToArray() ;
        }
    
    }
}
